package cn.com.bluemoon.daps.model.core.file.mysql;

import cn.com.bluemoon.daps.common.validation.illegal.IllegalChar;
import cn.com.bluemoon.daps.model.core.file.IndexData;
import cn.com.bluemoon.daps.model.core.file.excel.converter.MyIndexMethodIntegerStringConverter;
import cn.com.bluemoon.daps.model.core.file.excel.converter.MyIndexTypeIntegerStringConverter;
import cn.com.bluemoon.daps.model.entity.DapDataModelSubordinateKey;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.ContentRowHeight;
import com.alibaba.excel.annotation.write.style.HeadRowHeight;
import lombok.Data;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 * <pre>
 *     序号	表名称	字段列表	索引名	索引描述	索引类型	索引方法
 * 1	b2b_User_Huanxin_Info	showp_order_id,shop_code	idx_soid_scode	店铺ID店铺编码	UNIQUE	BTREE
 * </pre>
 *
 * @author Jarod.Kong
 * @date 2021/2/7 16:51
 */
@Data
@ColumnWidth(20)
@HeadRowHeight(15)
@ContentRowHeight(20)
public class MySqlIndexData extends IndexData {

    @ExcelProperty("序号")
    @ColumnWidth(8)
    private Integer order;

    //    @NoSqlKeyword(dbtype = DbType.mysql, name = "表英文名")
    @IllegalChar(message = "表英文名存在非法字符")
    @ExcelProperty("表英文名")
    @NotNull(message = "表英文名不可为空")
    @Size(max = 64, message = "表英文名不可以大于{max}")
    private String tableName;

    @ExcelProperty("字段列表")
    @NotNull(message = "字段列表不允许为空")
    private String fieldNames;

    @ExcelProperty("索引名")
    @Size(max = 64, message = "索引名不可以大于{max}")
    private String indexName;

    @ExcelProperty("索引描述")
    @Size(max = 1024, message = "索引中文名不可以大于{max}")
    private String indexDesc;

    @ExcelProperty(value = "索引类型", converter = MyIndexTypeIntegerStringConverter.class)
    @NotNull(message = "索引类型不允许为空")
    private Integer indexType;

    @ExcelProperty(value = "索引方法", converter = MyIndexMethodIntegerStringConverter.class)
    @NotNull(message = "索引方法不允许为空")
    private Integer indexMethod;

    public static MySqlIndexData getInstance() {
        return new MySqlIndexData();
    }

    @Override
    public MySqlIndexData copyDbProperties0(DapDataModelSubordinateKey dbIndex) {
        super.copyDbProperties0(dbIndex);
        setTableName(dbIndex.getTableName());
        setIndexName(dbIndex.getKeyName());
        setIndexDesc(dbIndex.getKeyChinName());
        setIndexType(dbIndex.getKeyType());
        setIndexMethod(dbIndex.getKeyMethod());
        return this;
    }
}
